home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / doc / python-gnome2-desktop / examples / gnomeprint / example_11.py < prev    next >
Encoding:
Python Source  |  2009-03-14  |  2.2 KB  |  83 lines

  1. #! /usr/bin/env python
  2. #
  3. # *  example_11.c: sample gnome-print code
  4. # *
  5. # *  This program is free software; you can redistribute it and/or
  6. # *  modify it under the terms of the GNU Library General Public License
  7. # *  as published by the Free Software Foundation; either version 2 of
  8. # *  the License, or (at your option) any later version.
  9. # *
  10. # *  This program is distributed in the hope that it will be useful,
  11. # *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. # *  GNU Library General Public License for more details.
  14. # *
  15. # *  You should have received a copy of the GNU Library General Public
  16. # *  License along with this program; if not, write to the Free Software
  17. # *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. # *
  19. # *  Authors:
  20. # *    Chema Celorio <chema@ximian.com>
  21. # *    Chris Lahey <clahey@ximian.com>
  22. #    Python conversion:
  23. #      Gustavo J. A. M. Carneiro <gustavo@users.sf.net>
  24. # *
  25. # *  Copyright (C) 2002, 2003 Ximian Inc. and authors
  26. # *
  27. # */
  28.  
  29. #/*
  30. # * See README
  31. # */
  32.  
  33. import pygtk; pygtk.require("2.0")
  34. import gnomeprint, gnomeprint.ui
  35.  
  36. TEMP_FILE = "temp.ps"
  37.  
  38. format = "%%! PS-Adobe-3.0 \n"\
  39.      "1 setlinewidth\n"\
  40.      "newpath\n"\
  41.      "100 100 moveto\n"\
  42.      "600 600 lineto\n"\
  43.      "stroke\n"\
  44.      "/Helvetica findfont\n"\
  45.      "24 scalefont setfont\n"\
  46.      "100 230 moveto\n"\
  47.      "(My page size is %fx%f) show\n"\
  48.      "showpage";
  49.  
  50.  
  51. def my_print(job, preview):
  52.  
  53.     file_ = file(TEMP_FILE, "w")
  54.  
  55.     config = job.get_config()
  56.     width, height = gnomeprint.job_get_page_size_from_config(config)
  57.  
  58.     output = format % (width, height)
  59.     file_.write(output)
  60.  
  61.     # this is marked with GNOME_PRINT_UNSTABLE_API in the public headers
  62.     # OK. So this example becomes useless, I know.
  63.     #job.set_file(TEMP_FILE)
  64.  
  65.     if not preview:
  66.         job.print_()
  67.     else:
  68.         gnomeprint.ui.JobPreview(job, "Title goes here").show()
  69.  
  70.  
  71. job    = gnomeprint.Job(gnomeprint.config_default())
  72. dialog = gnomeprint.ui.Dialog(job, "Sample print dialog", 0)
  73.  
  74. # Run the dialog
  75. response = dialog.run()
  76. dialog.destroy()
  77. if response == gnomeprint.ui.DIALOG_RESPONSE_PRINT:
  78.     my_print(job, False)
  79. elif response == gnomeprint.ui.DIALOG_RESPONSE_PREVIEW:
  80.     my_print(job, True)
  81.  
  82.  
  83.